function Food(game) {
  do {
    this.row = Math.floor(Math.random() * game.row);
    this.col = Math.floor(Math.random() * game.col);
  } while (this.checkCrash(game.snake));
}

Food.prototype.render = function () {
  game.setHTML(this.row, this.col, './asset/food.png');
};

// 如果食物生成在蛇的身上，那么返回 true
Food.prototype.checkCrash = function (snake) {
  let ok = true;
  for (let block of snake.body) {
    if (block.row == this.row && block.col == this.col) {
      ok = false;
      break;
    }
  }
  return !ok;
};
